
import json
import uuid
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
import redis

from reportservice.helpers import ApiResponse
r = redis.StrictRedis(host='10.8.0.83', port=6379, db=0)

@csrf_exempt
@require_http_methods(["GET"])
def get_wt_info(request):
    '''扫码获取委托信息：工程编号，工程名称，委托单位，内网合同编号,施工单位，监理单位，见证人，见证人电话，见证号，委托人'''
    wt_key = request.GET.get('wt_key')
    wt_content = r.get(f"supervise:wenzhou:{wt_key}")
    content = json.loads(wt_content)
    return ApiResponse.success(content)


@csrf_exempt
@require_http_methods(["POST"])
def upload_wt_info(request):
    '''
    扫码获取委托信息：工程编号，工程名称，委托单位，内网合同编号,施工单位，监理单位，见证人，见证人电话，见证号，委托人
    
    '''
    wt_key = uuid.uuid4()
    content = json.loads(request.body)
    r.set(f"supervise:wenzhou:{wt_key}",json.dumps(content))
    return ApiResponse.success(wt_key)